package en.edu.zxj.orderservice.controller;

import en.edu.zxj.orderservice.constant.Constants;
import en.edu.zxj.orderservice.model.OrderInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * Description：
 *
 * @author: zxj
 * @date: 2024-09-20
 * @time: 16:05:20
 */
@RequestMapping("/order/producer")
@RestController
public class OrderProducerController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @RequestMapping("/createOrder")
    public String createOrder() {
        String orderId = UUID.randomUUID().toString();
        String orderName = "订单名称";
        Long price = 100L;
        // 1. 封装订单信息
        OrderInfo orderInfo = new OrderInfo(orderId, orderName, price);
        // 2. 发送消息
        rabbitTemplate.convertAndSend("", Constants.WORK_QUEUE_NAME, orderInfo);
        return "创建订单成功";
    }

    @RequestMapping("/createOrder2")
    public String createOrder2() {
        String orderId = UUID.randomUUID().toString();
        rabbitTemplate.convertAndSend("", Constants.WORK_QUEUE_NAME, orderId);
        return "创建订单成功";
    }
}
